package com.example.jwtauthdemo.controller;

import com.example.jwtauthdemo.model.Order;
import com.example.jwtauthdemo.service.OrderService;
import com.example.jwtauthdemo.util.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/orders")
public class OrderController {

    private final OrderService orderService;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    /**
     * 获取当前登录用户的订单列表
     */
    @GetMapping
    @PreAuthorize("isAuthenticated()")
    public Result<List<Order>> getCurrentUserOrders() {
        List<Order> orders = orderService.getOrdersByCurrentUser();
        return Result.success(orders);
    }
}